#ifndef APPLIST_H
#define APPLIST_H

#include <list>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/list.hpp>

#include <App.h>
#include <boost/circular_buffer.hpp>

/**
 * AppList class enable storing application and swap between it.
 * With this high level collection, you can get current displayed application
 * easily.
 */
class AppList {
public:
  AppList();

  /**
   * Add an application inside the collection. If less than 3 applications are inside
   * the collection, it put it inside the displayed applications
   * @param app the added application
   */
  void addApp(App* app);

  /**
   * Remove an application of the collection
   * @param app the application that need to be removed
   */
  void removeApp(App* app);
  //App* getActiveApps();

  /**
   * Get the application displayed in the left
   * @returns the application on the left
   */
  App* getLeftApp();

  /**
   * Get the application displayed in the middle
   * @returns the application on the middle
   */
  App* getMiddleApp();

  /**
   * Get the application displayed in the right
   * @returns the application on the right
   */
  App* getRightApp();

  /**
   * Get the application which is next to the current right one
   * Useful when you want to go to next application
   * @returns the application next to the current right one
   */
  App* getNextRightApp();

  /**
   * Get the application which is next to the current left one
   * Useful when you want to go to previous application
   * @returns the application next to the current left one
   */
  App* getNextLeftApp();

  /**
   * Swap to the next application
   * @returns the application next to the previous right one (entering application)
   */
  App* swapNext();

  /**
   * Swap to the previous application
   * @returns the application next to the previous left one (entering application)
   */
  App* swapPrec();

  ~AppList();
private:
  friend class boost::serialization::access;
  /**
   * Saves/Loads the AppList
   */
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version) {
    // note, version is always the latest when saving
    //ar & _appLeft;
    //ar & _appMiddle;
    //ar & _appRight;
    //ar & _currentDisplayedApps;
    ar & _list;
    ar & _appLeft;
    ar & _appMiddle;
    ar & _appRight;
  }

  //boost::circular_buffer<App*>* _currentDisplayedApps;
  std::list<App*>* _list;
  App* _appLeft;
  App* _appMiddle;
  App* _appRight;
};

#endif
